package com.zryc.shop.pms.controller;

import com.zryc.shop.base.Result;
import com.zryc.shop.pms.entity.ProductAttribute;
import com.zryc.shop.pms.entity.ProductAttributeCategory;
import com.zryc.shop.pms.service.IProductAttributeService;
import com.zryc.shop.ums.entity.Menu;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 商品属性参数表 前端控制器
 * </p>
 *
 * @author zhaozhao
 * @since 2024-01-18
 */
@RestController
@Api(tags = "商品属性参数管理接口列表")
@RequestMapping("/pms/productAttribute")
public class ProductAttributeController {

    @Autowired
    private IProductAttributeService productAttributeService;

    @GetMapping("/list/{id}")
    @ApiOperation("查询商品属性列表")
    public Result list(@PathVariable @ApiParam(value = "属性分类id") Integer id,
                       @RequestParam @ApiParam(value = "类型: 0-属性 1-参数", required = true, allowableValues = "0,1") Integer type,
                       @RequestParam(defaultValue = "1") @ApiParam(value = "页码", required = true) Integer pageNum,
                       @RequestParam(defaultValue = "10") @ApiParam(value = "每页大小", required = true) Integer pageSize) {
        return Result.ok(productAttributeService.list(id, type, pageNum, pageSize));
    }


    @PostMapping("/create")
    @ApiOperation("新增商品属性")
    public Result create(@RequestBody ProductAttribute productAttribute) {
        return Result.ok(productAttributeService.create(productAttribute));
    }


    @PostMapping("/update/{id}")
    @ApiOperation("修改属性")
    public Result detail(@PathVariable @ApiParam(value = "属性ID", required = true) Long id,
                         @RequestBody ProductAttribute productAttribute) {
        return Result.ok(productAttributeService.updateDetail(id, productAttribute));
    }

    @PostMapping("/delete")
    @ApiOperation("批量删除属性(参数)")
    public Result delete(@RequestParam @ApiParam(value = "属性ID列表", required = true, example = "1,2,3") String ids) {
        return Result.ok(productAttributeService.delete(ids));
    }

    @GetMapping("/{id}")
    @ApiOperation("查询详情")
    public Result detail(@PathVariable @ApiParam(value = "属性ID", required = true) Long id) {
        return Result.ok(productAttributeService.getById(id));
    }

}
